#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;

void solve()
{
    int n, d, k; cin >> n >> d >> k;
    unordered_map<int, int> ma1, ma2;
    for (int i = 0; i < k; i++)
    {
        int l, r; cin >> l >> r;
        ma1[l] += 1;
        ma2[r] += 1;
    }
    int ans1, ans2;
    int pos1 = 1, pos2 = 1;
    int num = 0;
    int l = 2, r = d + 1;
    for (int i = 1; i <= d; i++)
    {
        num += ma1[i];
    }
    ans1 = ans2 = num;
    while (r <= n)
    {
        num -= ma2[l - 1];
        num += ma1[r];
        if (num > ans1)
        {
            pos1 = l; ans1 = num;
        }
        if (num < ans2)
        {
            pos2 = l, ans2 = num;
        }
        l += 1; r += 1;
    }
    cout << pos1 << ' ' << pos2 << endl;
}

int main()
{
    int t; cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}